package com.boang.bank;

public class BankAccountManagerTest {

    public static void main(String[] args) {
        Bank bank = new Bank();
        BankAccount account = bank.createAccount("12345", 1000.0);

        Runnable depositTask = () -> {
            for (int i = 0; i < 100; i++) {
                account.deposit(10);
                System.out.println(Thread.currentThread().getName() + " deposited 10. Current balance: " + account.getBalance());
            }
        };

        Runnable withdrawTask = () -> {
            for (int i = 0; i < 100; i++) {
                try {
                    account.withdraw(50);
                    System.out.println(Thread.currentThread().getName() + " withdrew 50. Current balance: " + account.getBalance());
                } catch (InsufficientFundsException e) {
                    System.out.println(Thread.currentThread().getName() + " " + e.getMessage());
                }
            }
        };

        Thread thread1 = new Thread(depositTask, "Depositor-1");
        Thread thread2 = new Thread(depositTask, "Depositor-2");
        Thread thread3 = new Thread(withdrawTask, "Withdrawer-1");
        Thread thread4 = new Thread(withdrawTask, "Withdrawer-2");

        thread1.start();
        thread2.start();
        thread3.start();
        thread4.start();

        try {
            thread1.join();
            thread2.join();
            thread3.join();
            thread4.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("Final balance: " + account.getBalance());
    }
}